<?php
// incomplete object is bad... so...
define('APPDIR', __DIR__ . '/');
define('LIBDIR', APPDIR . '../lib/');
// use core
require_once LIBDIR . 'core.php';
require_once APPDIR . 'config.php';
Util_Config::env('dev');

// include config...
AppCore::using('Model_Base');
AppCore::using('Model_Commentor_Comment');
AppCore::using('Model_Commentor_User');

// use xml
AppCore::using('Util_Xml');

AppCore::using('Util_HttpRequest');
// test post
/**
 * $req = new Util_HttpRequest('http://localhost/commentor/server/', 'POST');
 * $req->setQueryData('<xml><tag>value</tag></xml>');
 * $res = $req->send();
 * AppCore::dump($res);
 * exit;
 */
// test rpc
AppCore::using('XmlRpc_Client');
$c = new XmlRpc_Client('http://localhost/commentor/server/', Util_Config::get('token'));

    echo '<pre>';
try {
/*
    // create a new user:
    $user = new Model_Commentor_User;
    $user->setActive(true)
         ->setUsername('New Test')
         ->setIp('127.0.0.3')
         ->setWeb('http://ccc.com');

    // save a new comment...
    $cmt = new Model_Commentor_Comment();
    $cmt->setActive(true)
        ->setTitle('asd ew comment!')
        ->setUser($user)
        ->setArticleId(122)
        ->setComment('xxxx stuff to put in \\n yeah!');
//    AppCore::dump($c->saveComment($cmt));
*/
    // get all...
    $cmts = $c->getCommentsByArticleId(1112);
    if (!is_array($cmts) || empty($cmts)) {
        exit('NOTHING FOUND!');
    }
    // AppCore::dump($cmts);
    foreach ($cmts as $cmt) {
        if ($cmt instanceof Model_Commentor_Comment) {
            echo '<b>id</b>         ' . $cmt->getID() . "\n";
            echo '<b>site id</b>    ' . $cmt->getSiteID() . "\n";
            echo '<b>title</b>      ' . $cmt->getTitle() . "\n";
            echo '<b>created by</b> <i>' . $cmt->getUser()->getUsername() . '</i> at ' . $cmt->getCreatedBy(+1100, 'jS M, Y H:iA') . "\n<hr />";
        }
    }
} catch (Exception $e) {
    // error!
    echo '<b>ERROR!</b>' . $e->getMessage();
    return false;
}
    echo '</pre>';
exit;
?>